<?php

namespace App\Repository;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;

trait Transformer
{
    /**
     * @return [type]        [description]
     */
    public function transformCollection($items = null)
    {
//        if(!$items){
//            $this->newQuery()->eagerLoadRelations();
//            $items = $this->model->get()->toArray();
//        }
        if ($items == null) return $items;

        if ($items instanceof Collection || is_array($items)) {
            foreach ($items as $key => $item) {
                $this->transform($item);
            }
            return $items;
        }

        $this->transform($items);
        return $items;


        //return array_map([$this, 'transform'], $items);
    }

    public abstract function transform(Model $item);
}
